using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class BlockButton : MonoBehaviour
{
    [SerializeField]
    GameObject m_Selected;

    int m_Index;
    Action<int> m_ClickCallBack;

    
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        Button button = GetComponent<Button>();
        button.onClick.AddListener(OnClick);
      
    }

    void OnClick()
    {
        if (m_ClickCallBack != null)
            m_ClickCallBack( m_Index );
    }

    public void SetButtonSprite( int index, Sprite spr)
    {
        var image = GetComponent<Image>();
        image.sprite = spr ;
    }
    public void DoInit( int index, Action<int> clickCallBack )
    {
        m_Index = index;
        m_ClickCallBack = clickCallBack;
        SetSelected(false);
    }
    // Update is called once per frame
    void Update()
    {
        
    }

    public void SetSelected( bool value )
    {
        m_Selected.SetActive(value);
    }
}
